import {React, useEffect} from 'react';

import {BrowserRouter as Router, Route, Link, Routes } from 'react-router-dom'

function Index() {
 
    useEffect(() => {
        console.log('来到首页');
    
    return () => { // 充当了componentWillUnmiunt生命周期
        console.log('离开了首页');
    }
    }, [])
    return <h2>这是首页</h2>
}

function List() {
    return <h2>这是列表页</h2>
}

function App() {
    return (
        <Router>
            <ul>
                <li><Link>首页</Link></li>
                <li><Link>首页</Link></li>
            </ul>
            <Routes>
                <Route path='/' element={<Index/>}></Route>
                <Route path='/list' element={<List/>}></Route>
            </Routes>
        </Router>
    )
}

export default App